package com.zycfc.zsf.boot.mybatis.dynamicdatasource;

import org.springframework.core.*;
import org.springframework.boot.*;
import org.springframework.boot.env.*;
import org.springframework.core.io.*;
import org.springframework.context.support.*;
import org.springframework.core.env.*;
import org.springframework.context.*;
import com.zycfc.zsf.boot.util.json.*;
import org.slf4j.*;

public class ApplicatonEnvironListener implements SpringApplicationRunListener, PriorityOrdered
{
    private static final Logger log;
    private SpringApplication application;
    private String[] args;
    
    public ApplicatonEnvironListener() {
    }
    
    public ApplicatonEnvironListener(final SpringApplication application, final String[] args) {
        this.application = application;
        this.args = args;
    }
    
    public void environmentPrepared(final ConfigurableEnvironment environment) {
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f*******ssss**********");
        final MutablePropertySources propertySources = environment.getPropertySources();
        final YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
        try {
            ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f*****************");
            propertySources.addLast((PropertySource)loader.load("dbConfig", (Resource)new ClassPathResource("config/demo/core/dao.yml")).get(0));
            propertySources.addLast((PropertySource)loader.load("db2dbConfig", (Resource)new ClassPathResource("config/demo/core/dao-2.yml")).get(0));
            propertySources.addLast((PropertySource)loader.load("application", (Resource)new ClassPathResource("application.yml")).get(0));
        }
        catch (Exception e) {
            ApplicatonEnvironListener.log.error("\u52a0\u8f7d\u5931\u8d25", (Throwable)e);
        }
        final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
        configurer.setPropertySources((PropertySources)propertySources);
    }
    
    public int getOrder() {
        return 1;
    }
    
    public void starting() {
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f*****a************");
    }
    
    public void contextPrepared(final ConfigurableApplicationContext context) {
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f******c***********");
    }
    
    public void contextLoaded(final ConfigurableApplicationContext context) {
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f**********d*******");
    }
    
    public void started(final ConfigurableApplicationContext context) {
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f******e***********");
    }
    
    public void running(final ConfigurableApplicationContext context) {
        for (final String str : this.args) {
            ApplicatonEnvironListener.log.info("----str=" + str);
        }
        ApplicatonEnvironListener.log.info(JsonUtils.objectToJson((Object)this.application));
        ApplicatonEnvironListener.log.info("---\u52a0\u8f7d\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u6210\u529f******f***********");
    }
    
    public void failed(final ConfigurableApplicationContext context, final Throwable exception) {
    }
    
    public SpringApplication getApplication() {
        return this.application;
    }
    
    public void setApplication(final SpringApplication application) {
        this.application = application;
    }
    
    public String[] getArgs() {
        return this.args;
    }
    
    public void setArgs(final String[] args) {
        this.args = args;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)ApplicatonEnvironListener.class);
    }
}
